<?php
    session_start();
    if(!isset($_SESSION['loggedin'])) header('Location: index.php');
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">

    <title>TestYourSelf - Start</title>

    <!-- Bootstrap core CSS -->
    <link href="../../bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/highscore.css" rel="stylesheet">
    <link href="css/template.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

    <div class="site-wrapper">

        <div class="site-wrapper-inner">

            <div class="cover-container">

                <div class="masthead clearfix">
                    <div class="inner">
                        <h3 class="masthead-brand">TestYourSelf</h3>
                        <ul class="nav masthead-nav">
                            <li><a href="select.php">Start</a></li>
                            <li class="active"><a href="#">Highscore</a></li>
                            <li><a href="profil.php">Profil</a></li>
                            <li><a href="logout.php">Logout</a></li>
                            <?php if(isset($_SESSION['isadmin']) && $_SESSION['isadmin']=="true"){ ?>
                            <li><a href="admin.php">Administration</a></li>
                            <?php } ?>
                        </ul>
                    </div>
                </div>


                <div class="inner cover">
                    <h1 class="cover-heading">Highscore</h1>

                    <table class="table alltable">
                    <thead>
                    <tr>
                        <th>Szenarios</th>
                        <th>Kategorien</th>
                        <th class="points">Punkte</th>
                        <th class="points">Rang</th>
                        <th class="points">Bester</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                        $szenariosurl = "http://localhost:8080/TestYourselfASE/rest/scenarios";
                        $szenariosfile = file_get_contents($szenariosurl);
                        $szenarios = json_decode($szenariosfile);
                        $cyclecolor = 0;
                        $points = 0;
                        foreach($szenarios as $szenario){

                            $szenariopointsurl = "http://localhost:8080/TestYourselfASE/rest/highscore/getTotalHighscore/".$szenario->Id."/".$_SESSION["userid"];
                            $szenariopointsfile = file_get_contents($szenariopointsurl);
                            $szenariopoints = json_decode($szenariopointsfile);

                            $szenariobestsurl = "http://localhost:8080/TestYourselfASE/rest/highscore/getHighscoreInformationToScenario/".$_SESSION["userid"]."/".$szenario->Id;
                            $szenariobestfile = file_get_contents($szenariobestsurl);
                            $szenariobestpoints = json_decode($szenariobestfile);

                            echo '<tr class="rowtop';
                            if ($cyclecolor == 0) echo ' rowcolora" ';
                            else echo ' rowcolorb" ';
                            echo '><td class="szenario">'.$szenario->Name.'</td><td class="category"></td><td class="points">'.$szenariopoints->Points.' Pkt.</td><td class="best">'.$szenariobestpoints->myStanding.'. Platz</td><td class="best">'.$szenariobestpoints->bestHighscore.' Pkt.</td></tr>';

                            $points += $szenariopoints->Points;
                            $categoriesurl = "http://localhost:8080/TestYourselfASE/rest/categories/".$szenario->Id;
                            $categoriesfile = file_get_contents($categoriesurl);
                            $categories = json_decode($categoriesfile);

                            foreach($categories as $category){

                                $categorypointsurl = "http://localhost:8080/TestYourselfASE/rest/highscore/getHighscoreToCategory/".$szenario->Id."/".$category->Id."/".$_SESSION["userid"];
                                $categorypointsfile = file_get_contents($categorypointsurl);
                                $categorypoints = json_decode($categorypointsfile);

                                $categorybestsurl = "http://localhost:8080/TestYourselfASE/rest/highscore/getHighscoreInformationToCategory/".$_SESSION["userid"]."/".$szenario->Id."/".$category->Id;
                                $categorybestfile = file_get_contents($categorybestsurl);
                                $categorybestpoints = json_decode($categorybestfile);

                                echo '<tr';
                                if ($cyclecolor == 0) echo ' class="rowcolora" ';
                                else echo ' class="rowcolorb" ';

                                echo '><td class="szenario"></td><td class="category">'.$category->Name.'</td><td class="points">'.$categorypoints->Points.' Pkt.</td><td class="best">'.$categorybestpoints->myStanding.'. Platz</td><td class="best">'.$categorybestpoints->bestHighscore.' Pkt.</td></tr>';
                            }
                            if ($cyclecolor == 0) $cyclecolor = 1;
                            else $cyclecolor = 0;

                        }

                        echo '<tr class="sumrow"><td colspan="4" class="sum">Gesamt</td><td class="sumpoints">'.$points.' Punkte</td></tr>';

                        ?>
                    </tbody>
                    </table>


                </div>

                <div class="mastfoot">
                    <div class="inner">
                        <p>by Christoph Schuster, Martin Schmied, Thomas Stoellner, Philipp Taeubel</p>
                    </div>
                </div>

            </div>

        </div>

    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="../../bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

